package clojuretest;

import java.util.ArrayList;

import clojuretest.model.Problem;
import clojuretest.model.EquipmentConfig;
import clojuretest.model.OS;
import clojuretest.model.Profile;

import clojure.lang.RT;
import clojure.lang.Var;

public class ClojureDemo {
	 public static void main(String[] args) throws Exception {
	        // Load the Clojure script -- as a side effect this initializes the runtime.
	        
		 	long b = System.currentTimeMillis();
		 	RT.loadResourceScript("clojuretest.clj");
	        Var canBeAdded = RT.var("user", "canBeAdded");
	        long e = System.currentTimeMillis();
	        System.out.println("It took "+(e-b)+ " milliseconds to intialize Clojure.");

	        // Average initializing time 5000 milliseconds
	        	           
	        ArrayList<Profile> profiles = new ArrayList<Profile>();
			
			Profile pr1 = new Profile("Ann", new EquipmentConfig(OS.ANDROID, 1), 5); //GPRS
			profiles.add(pr1);
			Profile pr2 = new Profile("John", new EquipmentConfig(OS.WINDOWS, 3), 2); //WIFI
			profiles.add(pr2);
			Profile pr3 = new Profile("Nick", new EquipmentConfig(OS.ANDROID, 2), 3); //NG
			profiles.add(pr3);
			Profile pr4 = new Profile("Bob", new EquipmentConfig(OS.ANDROID, 1), 4); //GPRS
			profiles.add(pr4);
			Profile pr5 = new Profile("Dick", new EquipmentConfig(OS.WINDOWS, 3), 4); //WIFI
			profiles.add(pr5);
	        
			Problem p1 = new Problem("Video problem", "2 + 2 = ?", "http://youtube.com", 4000);
	               	
	        b = System.currentTimeMillis();
	        for (Profile  pr : profiles)
			{
	        	
	        	Object result = canBeAdded.invoke(pr, pr.getActiveEquipmentConfig(), p1);
				
				 Boolean flag = Boolean.parseBoolean((String)result);
				 if (flag) 
					 System.out.println(pr.getNickName()+ " can be added.");
			}
	        e = System.currentTimeMillis();
	        System.out.println("It took "+(e-b)+ " milliseconds to form the list using Clojure.");	       
	        // Average execution time 0 milliseconds
	 }
}
